<template>
	<view class="fui-wrap">
		<fui-list>
			<fui-list-cell v-for="(item,index) in list" :key="index" arrow @click="clickItem(item)">
				<view class="item">
					<view class="line">
						<fui-text text="商户：" color="#afafaf" :size="28"></fui-text>
						<fui-text :text="item.merch_name" color="#000" :size="28"></fui-text>
					</view>
					<view class="line">
						<fui-text :text="item.settle_type=='after'?'账单：':'余额：'" color="#afafaf" :size="28"></fui-text>
						<merch-balance :balance="item.balance" :settle_type="item.settle_type"></merch-balance>
					</view>
				</view>
				<view class="status">
					<fui-tag text="选择" type="success"></fui-tag>
				</view>
			</fui-list-cell>
		</fui-list>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
		<filter :show-cancel="false" ref="filter" :param="param" @confirm="doSubmit"></filter>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {formatDuration,parseNumber} from '@/utils/util.js'
	import filter from '@/components/common/filter.vue';
	import merchBalance from '@/components/common/merch-balance.vue';
	export default {
		components:{
			filter:filter,
			merchBalance:merchBalance
		},
		data() {
			return {
				baseUrl:baseUrl,
				list:[],
				type:'',
				type_txt:{
					recharge:'店铺充值',
					send:'自营店铺发停车券'
				},
				param:{
					merch_name:'',
				}
			}
		},
		onLoad(e) {
			this.type=e.type;
			uni.setNavigationBarTitle({
				title:this.type_txt[e.type]
			});
			if(this.type=='recharge'){
				this.$refs.filter.show();
			}
			if(this.type=='send'){
				this.getList();
			}
		},
		methods: {
			...methods,
			formatDuration,
			parseNumber,
			doSubmit:function(param){
				this.param=param;
				this.list=[];
				this.getList();
			},
			clickItem:function(item){
				if(this.type=='recharge'){
					this.$navigateTo('parking/merch/recharge?merch_id='+item.id)
				}
				if(this.type=='send'){
					this.$navigateTo('parking/merch/send?merch_id='+item.id)
				}
			},
			getList:function(callback=false){
				this.showPopup=false;
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				this.$get('parking/merch/search',{
					...this.param,
					type:this.type
				},true).then(res=>{
					this.list=res;
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.item{
	width: 100%;
	.line{
		display: flex;
		height: 60rpx;
		line-height: 60rpx;
	}
}
</style>